********************************************************************************
*Table A2: Heterogeneity based on receiving a dose prior to the intervention   *
*Code to run this file: 													   *
*texdoc do "${workdir}\Do files\Table A2 - het dose.do"						   *
********************************************************************************

reg vacunada_int i.tratamiento##i.dosis_prev_int  
local n1 = subinstr(string(e(N),"%12.0fc")," ","",.) 
local r21 = string(e(r2), "%9.3f")  
  
eststo model1_d

reg vacunada_int i.tratamiento##i.dosis_prev_int subsidiado i.ips  i.strata
local n2 = subinstr(string(e(N),"%12.0fc")," ","",.) 
local r22 = string(e(r2), "%9.3f")  

eststo model2_d

local tratamiento_labels "Control Placebo Information `"Social norms"' Trust Framing"

// Generate the table with the estimated effects  
texdoc init "${tables}/TA2 het dose (m).tex", replace
texdoc write \begin{table}[h!]
texdoc write \centering
texdoc write \caption{\centering Effect on HPV vaccine uptake based on whether the girl received a dose before the intervention} 
texdoc write \small
texdoc write \label{hetdose}
texdoc write \begin{tabular}{p{0.5\linewidth}>{\hsize=0.8\hsize}p{0.25\linewidth}>{\hsize=0.8\hsize}p{0.25\linewidth}}
texdoc write \hline
texdoc write  & \multicolumn{1}{c}{Model 1} & \multicolumn{1}{c}{Model 2} \\
texdoc write \hline
texdoc write \addlinespace

texdoc write \textbf{Treatment} & & \\ 
// Write the estimates for i.tratamiento  
forval i=1(1)5 {   
  estimates restore model1_d   
  local b11 = string(_b[`i'.tratamiento], "%9.3f")  
  local se11 = string(_se[`i'.tratamiento], "%9.3f")  
  local pvalue11 = 2*ttail(e(df_r),abs(`b11'/`se11'))   
  stars `pvalue11'  
  local stars11 "`stars'"  
  
  estimates restore model2_d   
  local b21 = string(_b[`i'.tratamiento], "%9.3f")   
  local se21 = string(_se[`i'.tratamiento], "%9.3f")   
  local pvalue21 = 2*ttail(e(df_r),abs(`b21'/`se21'))   
  stars `pvalue21'  
  local stars21 "`stars'"  
  
  if `i' == 0 {   
    local trat_label "\ \ Control"   
  }   
  else if `i' == 1 {   
    local trat_label "\ \ Placebo"   
  }   
  else if `i' == 2 {   
    local trat_label "\ \ Information"   
  }   
  else if `i' == 3 {   
    local trat_label "\ \ Social norms"   
  }   
  else if `i' == 4 {   
    local trat_label "\ \ Trust"   
  }   
  else if `i' == 5 {   
    local trat_label "\ \ Framing"   
  }   
    
  // Write the results to the table   
  texdoc write  `trat_label' & `b11'`stars11' & `b21'`stars21' \\  
  texdoc write  & (`se11') & (`se21') \\  
}  
  
// Write the estimates for 1.dosis_prev_int  
estimates restore model1_d   
local b12 = string(_b[1.dosis_prev_int], "%9.3f")  
local se12 = string(_se[1.dosis_prev_int], "%9.3f")  
local pvalue12 = 2*ttail(e(df_r),abs(`b12'/`se12')) 
stars `pvalue12'  
local stars12 "`stars'"  
  
estimates restore model2_d   
local b22 = string(_b[1.dosis_prev_int], "%9.3f")   
local se22 = string(_se[1.dosis_prev_int], "%9.3f")   
local pvalue22 = 2*ttail(e(df_r),abs(`b22'/`se22'))   
stars `pvalue22'  
local stars22 "`stars'"  
  
texdoc write & & \\
texdoc write  \textbf{Girl has received a previous dose} & `b12'`stars12' & `b22'`stars22' \\  
texdoc write  & (`se12') & (`se22') \\  
  
texdoc write  \textbf{Treatment x Received a previous dose} & &  \\

// Write the estimates for i.tratamiento#1.dosis_prev_int  
forval i=1(1)5 {   
  estimates restore model1_d   
  local b13 = string(_b[`i'.tratamiento#1.dosis_prev_int], "%9.3f")  
  local se13 = string(_se[`i'.tratamiento#1.dosis_prev_int], "%9.3f")  
  local pvalue13 = 2*ttail(e(df_r),abs(`b13'/`se13'))    
  stars `pvalue13'  
  local stars13 "`stars'"  
  
  local cons1    = string( _b[_cons], "%9.3f")  
  local se_cons1 = string(_se[_cons], "%9.3f")  
  local pv_cons1 = 2*ttail(e(df_r),abs(`cons1'/`se_cons1'))  
  stars `pv_cons1'  
  local stars_cons1 "`stars'"
   
  estimates restore model2_d   
  local b23 = string(_b[`i'.tratamiento#1.dosis_prev_int], "%9.3f")   
  local se23 = string(_se[`i'.tratamiento#1.dosis_prev_int], "%9.3f")   
  local pvalue23 = 2*ttail(e(df_r),abs(`b23'/`se23'))   
  stars `pvalue23'  
  local stars23 "`stars'"  
 
  local cons2    = string( _b[_cons], "%9.3f")  
  local se_cons2 = string(_se[_cons], "%9.3f")  
  local pv_cons2 = 2*ttail(e(df_r),abs(`cons2'/`se_cons2'))   
  stars `pv_cons2'  
  local stars_cons2 "`stars'"
  
  if `i' == 0 {   
    local trat_int_label "\ \ Control \& Previous dose"   
  }   
  else if `i' == 1 {   
    local trat_int_label "\ \ Placebo \& Previous dose"   
  }   
  else if `i' == 2 {   
    local trat_int_label "\ \ Information \& Previous dose"   
  }   
  else if `i' == 3 {   
    local trat_int_label "\ \ Social norms \& Previous dose"   
  }   
  else if `i' == 4 {   
    local trat_int_label "\ \ Trust \& Previous dose"   
  }   
  else if `i' == 5 {   
    local trat_int_label "\ \ Framing \& Previous dose"   
  }   
    
  // Write the results to the table   
  texdoc write  `trat_int_label' & `b13'`stars13' & `b23'`stars23' \\  
  texdoc write  & (`se13') & (`se23') \\  
}  

texdoc write & & \\
 texdoc write Constant  & \multicolumn{1}{c}{`cons1' `stars_cons1'} & \multicolumn{1}{c}{`cons2' `stars_cons2'}  \\
texdoc write 	& \multicolumn{1}{c}{(`se_cons1')}  & \multicolumn{1}{c}{(`se_cons2')}  \\

texdoc write \addlinespace
texdoc write \hline
texdoc write Strata fixed effects & No & Yes \\
texdoc write Covariates & No & Yes  \\
texdoc write R-squared & `r21' & `r22' \\
texdoc write Observations & `n1'  & `n2'  \\

texdoc write \hline	
texdoc write \addlinespace
texdoc write \multicolumn{3}{p{\linewidth}}{\footnotesize Models 1 and 2 estimate the interaction between the treatment variable and whether the girl is receiving her first or second dose of the HPV vaccine. Since the HPV vaccination scheme consists of only two doses, a girl is considered to be receiving the second dose if she had already received one prior to the intervention; otherwise, it is her first dose. Model 2 includes as covariates whether a girl is under subsidized scheme, healthcare center visited, and the stratification variable which includes level of income and age. Standard errors in parentheses. *** p$<$0.001, ** p$<$0.01, * p$<$0.5} \\


// Close the table  
texdoc write \end{tabular}  
texdoc write \end{table}  
texdoc close